package com.blb.marry.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.blb.marry.entity.Hotel;
import com.blb.marry.service.HotelService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

import java.util.List;

/**
 * @author lvtian
 * @date 2023/1/13 11:43
 */
@Controller
public class HotelController {
    @Autowired
    private HotelService hotelService;

    @RequestMapping("/selectHotelPage")
    public String selectHotelPage(@RequestParam( value = "current",required = false,defaultValue = "1") Integer current, Model model){
        Page<Hotel> page =  new Page<Hotel>(current, 8);
        IPage<Hotel> hotelPage = hotelService.selectHotelPage(page);
        List<Hotel> hotels = hotelPage.getRecords();
        model.addAttribute("hotels",hotels);
        model.addAttribute("page1",page);
        System.out.println(page.getCurrent());
        return "forward:/field.html";
    }
}
